package com.zhou.spring.scope;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author zhouyanxiang
 * @create 2020-09-2020/9/24-15:01
 */
public class SingletonTest {

    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        A a = ctx.getBean("A", A.class);
        System.out.println(a);
        System.out.println(a.getB());
        System.out.println(a.getB().getC());

        System.out.println("=============");

        A a1 = ctx.getBean("A",A.class);
        System.out.println(a1);
        System.out.println(a1.getB());
        System.out.println(a1.getB().getC());
        System.out.println("实例化多个单例对象都是指向的同一个内存地址: " + (a == a1));

        System.out.println("=============");

        B b1 = ctx.getBean("B",B.class);
        B b2 = ctx.getBean("B",B.class);
        B b3 = ctx.getBean("B",B.class);
        System.out.println("b1 : " + b1);
        System.out.println("b2 : " + b2);
        System.out.println("b3 : " + b3);


    }

}
